package gov.dhs.cis.soa.data;

import gov.dhs.cis.soa.Constants;
import gov.dhs.cis.soa.Utils;
import gov.dhs.cis.soa.Constants.EntityType;

import java.sql.Timestamp;


class ITypes {
	public String cd;
	public String name;
	
	public ITypes(String s1, String s2) {
		cd = s1; name = s2;
	}
}

public class Interface extends AbstractSOAData {
	public static ITypes[] typeObjs = { 
		new ITypes("SI", "3rd Party System Interface"), new ITypes("ASI", "Agency System Interface"),
		new ITypes("CUI", "COTS Portal"), new ITypes("EUI", "External Portal"), new ITypes("IUI", "Internal Portal"),
		new ITypes("II", "IOE Internal Interface"), new ITypes("USI", "USCIS System Interface") 
		};
	
	public static ITypes unKnownIType = new ITypes("UN", "Un Known");

	public static final String STEREO_TYPE = "Interface";

	public int id;
	public String name;
	public transient String descText;
	public String stereotype;
	public String wipt;
	public String release;
	public int maturity;
	public String sysextentity;
	public String agency;
	public String actorusing;
	
	public transient String l3busprocname;
	public String usecase;		//added on 07/19/2010 - RSingh
	public String reltosys;
	public String dirprimdataflow;
	public String reqdataflow;
	public String respdataflow;
	public String ioeagent;
	public String serviceref;
	public String mep;
	public String candUseOfEntServ;
	public String neededby;
	public String integHosting;
	public transient String designAspects;
	public transient String assumptions;

	public transient Timestamp createdDt = new Timestamp(System.currentTimeMillis());

	public Description desc;
	
	@Override
	public String toString() {
		StringBuffer ret = new StringBuffer("Interface [id=" + id + ", name=" + name + ", Type=" + stereotype + "]");
		return ret.toString();
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Interface other = (Interface) obj;
		if (id == other.id && stereotype.equalsIgnoreCase(other.stereotype) && name.equalsIgnoreCase(other.name))
			return true;
		return false;
	}
	
	public void createDescription() {
		StringBuffer txt = new StringBuffer();
		if(Utils.isEmpty(descText))
			descText = "";
		txt.append(Constants.NL+"Description = " + descText);
		if(Utils.isEmpty(l3busprocname))
			l3busprocname = "";
		txt.append(Constants.NL+"Business Process = " + l3busprocname);
		if(Utils.isEmpty(designAspects))
			designAspects = "";
		txt.append(Constants.NL+"Design Aspects = " + designAspects);
		if(Utils.isEmpty(assumptions))
			assumptions = "";
		txt.append(Constants.NL+"Assumptions = " + assumptions);
		
		desc = Utils.prepareDescObj(txt.toString(), EntityType.INTR);
	}

	public static String getInterfaceTypeCd_del(String fullName) {
		String tName = fullName;
		if(!Utils.isEmpty(tName))
			tName = tName.trim();
		for(ITypes typeO : typeObjs) {
			if(typeO.name.equalsIgnoreCase(tName))
				return typeO.cd;
		}
		return unKnownIType.cd;
	}
	
	public static String getInterfaceTypeName_del(String typeCd) {
		String tCd = typeCd;
		if(!Utils.isEmpty(tCd))
			tCd = tCd.trim();
		for(ITypes typeO : typeObjs) {
			if(typeO.cd.equalsIgnoreCase(tCd))
				return typeO.name;
		}
		return unKnownIType.name;
	}
	public static String[] getAllInterfaceTypeNames_del() {
		String[] ret = new String[typeObjs.length];
		int i = 0;
		for(ITypes typeO : typeObjs) {
			ret[i++] = typeO.name;
		}
		return ret;
	}
	
	/*
	public void setDataList(List<RelatedDataReference> inList, List<RelatedDataReference> outList) {
		if(dataList == null)
			dataList = new ArrayList<RelatedDataReference>();
		else
			dataList.clear();
		if(inList != null && inList.size() > 0)
			dataList.addAll(inList);
		if(outList != null && outList.size() > 0)
			dataList.addAll(outList);
	}
	*/
	
//	public static String getUMLId(int entityId) {
//	return EntityType.INTR + "_" + entityId;
//}

	@Override
	public long getId() {
		return id;
	}
	@Override
	public String getHashableId() {
		return name;
	}
	
	@Override
	public EntityType getUMLType() {
		return EntityType.INTR;
	}
}
